<template>
	<el-config-provider :locale="locale" :size="size">
		<router-view />
	</el-config-provider>
</template>

<script setup lang="ts">
import { computed, nextTick, onMounted } from 'vue'
import { RouterView } from 'vue-router'
import { useTitle } from '@vueuse/core'
import store from '@/store'
import { useI18n } from 'vue-i18n'
import { messages } from '@/i18n'
import { handleThemeStyle } from '@/utils/theme'
import { postApi } from './api/api'

const { t } = useI18n()
const locale = computed(() => messages[store.appStore.language].el)
const size = computed(() => store.appStore.componentSize)

// 设置标题
useTitle(import.meta.env.VITE_WEB_TITLE)

onMounted(() => {
    if (localStorage.getItem('token')) {
        setTimeout(() => {
            // 查询库存
            postApi('/api/strator/product/warning').then((result) => {
                // console.log(result.data.total);
                // 库存管理节点
                // const kcyjmenuclass = document.querySelector('.kcyjmenuclass')?.querySelector('.el-sub-menu__title')?.querySelector('span').innerText;
                // const kcyjclass = document.querySelector('.kcyjclass').innerText;
                // console.log(kcyjmenuclass);
                // console.log(kcyjclass);
                if (result.data.total > 0) {
                    store.routerStore.updateNum(result.data.total)
                    // document.querySelector('.kcyjmenuclass')?.querySelector('.el-sub-menu__title')?.querySelector('span').innerText = `库存管理(${result.data.total})`;
                    // document.querySelector('.kcyjclass').innerText = `库存预警(${result.data.total})`
                }
            }).catch((err) => {
                
            });
        }, 1500)
    }
	nextTick(() => {
		// 初始化主题样式
		handleThemeStyle(store.appStore.theme)
	})
})
</script>
